import Mock from 'mockjs'
import express from 'express'
import cors from 'cors'
import dotenv from 'dotenv'
dotenv.config()

const app = express()
app.use(cors())
app.use(express.json())

let data = Mock.mock({
  'arr|20': [
    {
      'id|+1': 1,
      'name': () => `分类${Mock.Random.integer(1, 1000)}`,
      'sortVal': () => Mock.Random.integer(1, 100),
      'time': () => Mock.Random.date('yyyy-MM-dd')
    }
  ],
});
let result = {
  code: 200,
  data: {
    list: data.arr,
    total: data.arr.length
  }
}
// 分类接口（与前端List.vue对接）
app.get('/categories', (req, res) => {
  const { pageNumber = 1, pageSize = 10 } = req.query
  // 这里可以连接真实数据库
  res.json(result)
})

const PORT = process.env.PORT || 3000
app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`)
})